{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import QUANTAXIS as QA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "user= QA.QA_User(username='yutiansut',password='940809')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(True, '6aebb77b-2482-11e9-812b-9cb6d020b9c2')"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.subscribe_strategy('s1_jm',1)\n",
    "user.subscribe_strategy('s1_j',2)\n",
    "user.subscribe_strategy('s1_rb',4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end</th>\n",
       "      <th>lasttime</th>\n",
       "      <th>start</th>\n",
       "      <th>status</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>uuid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>6aeb9274-2482-11e9-bf35-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-01</td>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-02-12</td>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          end  lasttime       start   status strategy_id  \\\n",
       "0  2019-01-31         1  2019-01-30  running       s1_jm   \n",
       "1  2019-02-01         2  2019-01-30  running        s1_j   \n",
       "2  2019-02-12         4  2019-01-30  running       s1_rb   \n",
       "\n",
       "                                   uuid  \n",
       "0  6aeb9274-2482-11e9-bf35-9cb6d020b9c2  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.subscribed_strategy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cost_coins</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>start</th>\n",
       "      <th>last</th>\n",
       "      <th>strategy_uuid</th>\n",
       "      <th>event</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>1</td>\n",
       "      <td>6aeb9274-2482-11e9-bf35-9cb6d020b9c2</td>\n",
       "      <td>subscribe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>2</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "      <td>subscribe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>4</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "      <td>subscribe</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   cost_coins strategy_id       start  last  \\\n",
       "0          10       s1_jm  2019-01-30     1   \n",
       "1          10        s1_j  2019-01-30     2   \n",
       "2          10       s1_rb  2019-01-30     4   \n",
       "\n",
       "                          strategy_uuid      event  \n",
       "0  6aeb9274-2482-11e9-bf35-9cb6d020b9c2  subscribe  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2  subscribe  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2  subscribe  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.coins_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9970"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.coins"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "user.unsubscribe_stratgy('s1_jm')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end</th>\n",
       "      <th>lasttime</th>\n",
       "      <th>start</th>\n",
       "      <th>status</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>uuid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>canceled</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>6aeb9274-2482-11e9-bf35-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-01</td>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-02-12</td>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          end  lasttime       start    status strategy_id  \\\n",
       "0  2019-01-31         1  2019-01-30  canceled       s1_jm   \n",
       "1  2019-02-01         2  2019-01-30   running        s1_j   \n",
       "2  2019-02-12         4  2019-01-30   running       s1_rb   \n",
       "\n",
       "                                   uuid  \n",
       "0  6aeb9274-2482-11e9-bf35-9cb6d020b9c2  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.subscribed_strategy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>cost_coins</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>start</th>\n",
       "      <th>last</th>\n",
       "      <th>strategy_uuid</th>\n",
       "      <th>event</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>1</td>\n",
       "      <td>6aeb9274-2482-11e9-bf35-9cb6d020b9c2</td>\n",
       "      <td>subscribe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>2</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "      <td>subscribe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>10</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>4</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "      <td>subscribe</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>0</td>\n",
       "      <td>6af71038-2482-11e9-a5ce-9cb6d020b9c2</td>\n",
       "      <td>unsubscribe</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   cost_coins strategy_id       start  last  \\\n",
       "0          10       s1_jm  2019-01-30     1   \n",
       "1          10        s1_j  2019-01-30     2   \n",
       "2          10       s1_rb  2019-01-30     4   \n",
       "3           0       s1_jm  2019-01-30     0   \n",
       "\n",
       "                          strategy_uuid        event  \n",
       "0  6aeb9274-2482-11e9-bf35-9cb6d020b9c2    subscribe  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2    subscribe  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2    subscribe  \n",
       "3  6af71038-2482-11e9-a5ce-9cb6d020b9c2  unsubscribe  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.coins_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pd.Timestamp('2018-11-05')-pd.Timestamp('2018-11-10')>datetime.timedelta(days=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end</th>\n",
       "      <th>lasttime</th>\n",
       "      <th>start</th>\n",
       "      <th>status</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>uuid</th>\n",
       "      <th>remains</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-01</td>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "      <td>2 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-02-12</td>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "      <td>13 days</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          end  lasttime       start   status strategy_id  \\\n",
       "1  2019-02-01         2  2019-01-30  running        s1_j   \n",
       "2  2019-02-12         4  2019-01-30  running       s1_rb   \n",
       "\n",
       "                                   uuid remains  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2  2 days  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2 13 days  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.subscribing_strategy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end</th>\n",
       "      <th>lasttime</th>\n",
       "      <th>start</th>\n",
       "      <th>status</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>uuid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>canceled</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>6aeb9274-2482-11e9-bf35-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-01</td>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-02-12</td>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          end  lasttime       start    status strategy_id  \\\n",
       "0  2019-01-31         1  2019-01-30  canceled       s1_jm   \n",
       "1  2019-02-01         2  2019-01-30   running        s1_j   \n",
       "2  2019-02-12         4  2019-01-30   running       s1_rb   \n",
       "\n",
       "                                   uuid  \n",
       "0  6aeb9274-2482-11e9-bf35-9cb6d020b9c2  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user.subscribed_strategy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "user.save()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 账户的同步和更新\n",
    "\n",
    "QA_User在初始化的时候会自动同步数据库, 更新自己"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "user1= QA.QA_User(username='yutiansut',password='940809')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_USER USER_YjEUNwWt with 0 portfolio: {} >"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user1.sync()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'user_cookie': 'USER_YjEUNwWt',\n",
       " 'username': 'yutiansut',\n",
       " 'password': '940809',\n",
       " 'wechat_id': None,\n",
       " 'phone': 'defalut',\n",
       " 'level': 'l1',\n",
       " 'utype': 'guests',\n",
       " 'coins': 9970,\n",
       " 'coins_history': [[10,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   1,\n",
       "   '6aeb9274-2482-11e9-bf35-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_j',\n",
       "   '2019-01-30',\n",
       "   2,\n",
       "   '6aebb77a-2482-11e9-a778-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_rb',\n",
       "   '2019-01-30',\n",
       "   4,\n",
       "   '6aebb77b-2482-11e9-812b-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [0,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   0,\n",
       "   '6af71038-2482-11e9-a5ce-9cb6d020b9c2',\n",
       "   'unsubscribe']],\n",
       " 'money': 0,\n",
       " 'subuscribed_strategy': {'s1_jm': {'lasttime': 1,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_jm',\n",
       "   'end': '2019-01-31',\n",
       "   'status': 'canceled',\n",
       "   'uuid': '6aeb9274-2482-11e9-bf35-9cb6d020b9c2'},\n",
       "  's1_j': {'lasttime': 2,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_j',\n",
       "   'end': '2019-02-01',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77a-2482-11e9-a778-9cb6d020b9c2'},\n",
       "  's1_rb': {'lasttime': 4,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_rb',\n",
       "   'end': '2019-02-12',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77b-2482-11e9-812b-9cb6d020b9c2'}},\n",
       " 'subscribed_code': [],\n",
       " 'portfolio_list': [],\n",
       " 'lastupdatetime': '2019-01-30 19:30:17.217283'}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user1.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "user1.money=200000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "user1.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'user_cookie': 'USER_YjEUNwWt',\n",
       " 'username': 'yutiansut',\n",
       " 'password': '940809',\n",
       " 'wechat_id': None,\n",
       " 'phone': 'defalut',\n",
       " 'level': 'l1',\n",
       " 'utype': 'guests',\n",
       " 'coins': 9970,\n",
       " 'coins_history': [[10,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   1,\n",
       "   '6aeb9274-2482-11e9-bf35-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_j',\n",
       "   '2019-01-30',\n",
       "   2,\n",
       "   '6aebb77a-2482-11e9-a778-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_rb',\n",
       "   '2019-01-30',\n",
       "   4,\n",
       "   '6aebb77b-2482-11e9-812b-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [0,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   0,\n",
       "   '6af71038-2482-11e9-a5ce-9cb6d020b9c2',\n",
       "   'unsubscribe']],\n",
       " 'money': 200000,\n",
       " 'subuscribed_strategy': {'s1_jm': {'lasttime': 1,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_jm',\n",
       "   'end': '2019-01-31',\n",
       "   'status': 'canceled',\n",
       "   'uuid': '6aeb9274-2482-11e9-bf35-9cb6d020b9c2'},\n",
       "  's1_j': {'lasttime': 2,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_j',\n",
       "   'end': '2019-02-01',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77a-2482-11e9-a778-9cb6d020b9c2'},\n",
       "  's1_rb': {'lasttime': 4,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_rb',\n",
       "   'end': '2019-02-12',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77b-2482-11e9-812b-9cb6d020b9c2'}},\n",
       " 'subscribed_code': [],\n",
       " 'portfolio_list': [],\n",
       " 'lastupdatetime': '2019-01-30 19:30:17.255296'}"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user1.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'user_cookie': 'USER_YjEUNwWt',\n",
       " 'username': 'yutiansut',\n",
       " 'password': '940809',\n",
       " 'wechat_id': None,\n",
       " 'phone': 'defalut',\n",
       " 'level': 'l1',\n",
       " 'utype': 'guests',\n",
       " 'coins': 9970,\n",
       " 'coins_history': [[10,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   1,\n",
       "   '6aeb9274-2482-11e9-bf35-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_j',\n",
       "   '2019-01-30',\n",
       "   2,\n",
       "   '6aebb77a-2482-11e9-a778-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_rb',\n",
       "   '2019-01-30',\n",
       "   4,\n",
       "   '6aebb77b-2482-11e9-812b-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [0,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   0,\n",
       "   '6af71038-2482-11e9-a5ce-9cb6d020b9c2',\n",
       "   'unsubscribe']],\n",
       " 'money': 200000,\n",
       " 'subuscribed_strategy': {'s1_jm': {'lasttime': 1,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_jm',\n",
       "   'end': '2019-01-31',\n",
       "   'status': 'canceled',\n",
       "   'uuid': '6aeb9274-2482-11e9-bf35-9cb6d020b9c2'},\n",
       "  's1_j': {'lasttime': 2,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_j',\n",
       "   'end': '2019-02-01',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77a-2482-11e9-a778-9cb6d020b9c2'},\n",
       "  's1_rb': {'lasttime': 4,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_rb',\n",
       "   'end': '2019-02-12',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77b-2482-11e9-812b-9cb6d020b9c2'}},\n",
       " 'subscribed_code': [],\n",
       " 'portfolio_list': [],\n",
       " 'lastupdatetime': '2019-01-30 19:30:17.278445'}"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_User(username='yutiansut',password='940809').message"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 讨论下 QAUSER的下挂Portfolio/Account"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "admin=QA.QA_User(username='yutiansut',password='940809')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin.portfolio_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Portfolio RB_PORTFOLIO with 0 Accounts >"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin.new_portfolio('RB_PORTFOLIO')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "RB_Portfolio=admin.get_portfolio('RB_PORTFOLIO')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account test1 market: stock_cn>"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.new_account(account_cookie='test1',init_cash=200000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB_PORTFOLIO': < QA_Portfolio RB_PORTFOLIO with 1 Accounts >}"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin.portfolio_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'test1': < QA_Account test1 market: stock_cn>}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.accounts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'USER_YjEUNwWt'"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.user_cookie"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Portfolio RB_PORTFOLIO with 1 Accounts >"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc1=RB_Portfolio['test1']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account test1 market: stock_cn>"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_USER USER_YjEUNwWt with 1 portfolio: {'RB_PORTFOLIO': < QA_Portfolio RB_PORTFOLIO with 1 Accounts >} >"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 让account发生一些行为: 交易等"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc1.receive_simpledeal('000001',20, 2000,QA.ORDER_DIRECTION.BUY, '2019-01-25')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 回来查看 QAUSER/ QAPORTFOLIO\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100000000, 99800000]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n",
    "\"\"\"\n",
    "当组合产生一个子账户的时候, 会统一扣减一个值\n",
    "\n",
    "至于子账户的内部行为, 在PORTFOLIO.cash的部分不加以体现\n",
    "\n",
    "\"\"\"\n",
    "RB_Portfolio.cash # 组合和子账户之间的交互"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000001</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>159990.0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     datetime    code  price  amount      cash order_id realorder_id trade_id  \\\n",
       "0  2019-01-25  000001     20    2000  159990.0     None         None     None   \n",
       "\n",
       "  account_cookie  commission  tax message  frozen  \n",
       "0          test1        10.0    0    None       0  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc2= RB_Portfolio.new_account(account_cookie='test2',init_cash=500000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc2.receive_simpledeal('000002',20, 2000,QA.ORDER_DIRECTION.BUY, '2019-01-25')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000001</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>159990.0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000002</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>459990.0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test2</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     datetime    code  price  amount      cash order_id realorder_id trade_id  \\\n",
       "0  2019-01-25  000001     20    2000  159990.0     None         None     None   \n",
       "0  2019-01-25  000002     20    2000  459990.0     None         None     None   \n",
       "\n",
       "  account_cookie  commission  tax message  frozen  \n",
       "0          test1        10.0    0    None       0  \n",
       "0          test2        10.0    0    None       0  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc3= RB_Portfolio.new_account(account_cookie='test3_future',init_cash=500000, market_type=QA.MARKET_TYPE.FUTURE_CN)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'future_cn'"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc3.market_type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Account test3_future market: future_cn>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc3.receive_simpledeal('RB1905',3509, 2,QA.ORDER_DIRECTION.BUY_OPEN, '2019-01-25')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "acc3.receive_simpledeal('J1905',1800, 2,QA.ORDER_DIRECTION.BUY_OPEN, '2019-01-25')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000001</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>159990.0000</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test1</td>\n",
       "      <td>10.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000002</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>459990.0000</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test2</td>\n",
       "      <td>10.0000</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>RB1905</td>\n",
       "      <td>3509</td>\n",
       "      <td>2</td>\n",
       "      <td>492981.2982</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test3_future</td>\n",
       "      <td>0.7018</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>7018</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>J1905</td>\n",
       "      <td>1800</td>\n",
       "      <td>2</td>\n",
       "      <td>489381.0822</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test3_future</td>\n",
       "      <td>0.2160</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>3600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     datetime    code  price  amount         cash order_id realorder_id  \\\n",
       "0  2019-01-25  000001     20    2000  159990.0000     None         None   \n",
       "0  2019-01-25  000002     20    2000  459990.0000     None         None   \n",
       "0  2019-01-25  RB1905   3509       2  492981.2982     None         None   \n",
       "1  2019-01-25   J1905   1800       2  489381.0822     None         None   \n",
       "\n",
       "  trade_id account_cookie  commission  tax message  frozen  \n",
       "0     None          test1     10.0000    0    None       0  \n",
       "0     None          test2     10.0000    0    None       0  \n",
       "0     None   test3_future      0.7018    0    None    7018  \n",
       "1     None   test3_future      0.2160    0    None    3600  "
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "\n",
    "history_table 展示了当前的所有子账户的交易\n",
    "\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "RB_Portfolio.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ERROR : CODE 000001 TIME 2019-01-28 09:31:00  AMOUNT 100 TOWARDS -1\n",
      "卖出仓位不足\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.send_order('test1','000001',100,'2019-01-28',QA.ORDER_DIRECTION.SELL,price=22, order_model=QA.ORDER_MODEL.LIMIT,amount_model=QA.AMOUNT_MODEL.BY_AMOUNT)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['2019-01-25',\n",
       "  'RB1905',\n",
       "  3509,\n",
       "  2,\n",
       "  492981.2982,\n",
       "  None,\n",
       "  None,\n",
       "  None,\n",
       "  'test3_future',\n",
       "  0.7018,\n",
       "  0,\n",
       "  None,\n",
       "  7018],\n",
       " ['2019-01-25',\n",
       "  'J1905',\n",
       "  1800,\n",
       "  2,\n",
       "  489381.0822,\n",
       "  None,\n",
       "  None,\n",
       "  None,\n",
       "  'test3_future',\n",
       "  0.216,\n",
       "  0,\n",
       "  None,\n",
       "  3600]]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.history[0][2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Portfolio RB_PORTFOLIO with 3 Accounts >"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin['RB_PORTFOLIO']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#   开放成HTTP 端口, 被WEBSERVER实现 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'user_cookie': 'USER_YjEUNwWt',\n",
       " 'username': 'yutiansut',\n",
       " 'password': '940809',\n",
       " 'wechat_id': None,\n",
       " 'phone': 'defalut',\n",
       " 'level': 'l1',\n",
       " 'utype': 'guests',\n",
       " 'coins': 9970,\n",
       " 'coins_history': [[10,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   1,\n",
       "   '6aeb9274-2482-11e9-bf35-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_j',\n",
       "   '2019-01-30',\n",
       "   2,\n",
       "   '6aebb77a-2482-11e9-a778-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [10,\n",
       "   's1_rb',\n",
       "   '2019-01-30',\n",
       "   4,\n",
       "   '6aebb77b-2482-11e9-812b-9cb6d020b9c2',\n",
       "   'subscribe'],\n",
       "  [0,\n",
       "   's1_jm',\n",
       "   '2019-01-30',\n",
       "   0,\n",
       "   '6af71038-2482-11e9-a5ce-9cb6d020b9c2',\n",
       "   'unsubscribe']],\n",
       " 'money': 200000,\n",
       " 'subuscribed_strategy': {'s1_jm': {'lasttime': 1,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_jm',\n",
       "   'end': '2019-01-31',\n",
       "   'status': 'canceled',\n",
       "   'uuid': '6aeb9274-2482-11e9-bf35-9cb6d020b9c2'},\n",
       "  's1_j': {'lasttime': 2,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_j',\n",
       "   'end': '2019-02-01',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77a-2482-11e9-a778-9cb6d020b9c2'},\n",
       "  's1_rb': {'lasttime': 4,\n",
       "   'start': '2019-01-30',\n",
       "   'strategy_id': 's1_rb',\n",
       "   'end': '2019-02-12',\n",
       "   'status': 'running',\n",
       "   'uuid': '6aebb77b-2482-11e9-812b-9cb6d020b9c2'}},\n",
       " 'subscribed_code': [],\n",
       " 'portfolio_list': ['RB_PORTFOLIO'],\n",
       " 'lastupdatetime': '2019-01-30 19:30:17.751706'}"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[100000000, 99800000, 99300000, 98800000]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "RB_Portfolio.cash"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000001</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>159990.0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     datetime    code  price  amount      cash order_id realorder_id trade_id  \\\n",
       "0  2019-01-25  000001     20    2000  159990.0     None         None     None   \n",
       "\n",
       "  account_cookie  commission  tax message  frozen  \n",
       "0          test1        10.0    0    None       0  "
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "acc1.history_table"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>end</th>\n",
       "      <th>lasttime</th>\n",
       "      <th>start</th>\n",
       "      <th>status</th>\n",
       "      <th>strategy_id</th>\n",
       "      <th>uuid</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-31</td>\n",
       "      <td>1</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>canceled</td>\n",
       "      <td>s1_jm</td>\n",
       "      <td>6aeb9274-2482-11e9-bf35-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2019-02-01</td>\n",
       "      <td>2</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_j</td>\n",
       "      <td>6aebb77a-2482-11e9-a778-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2019-02-12</td>\n",
       "      <td>4</td>\n",
       "      <td>2019-01-30</td>\n",
       "      <td>running</td>\n",
       "      <td>s1_rb</td>\n",
       "      <td>6aebb77b-2482-11e9-812b-9cb6d020b9c2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          end  lasttime       start    status strategy_id  \\\n",
       "0  2019-01-31         1  2019-01-30  canceled       s1_jm   \n",
       "1  2019-02-01         2  2019-01-30   running        s1_j   \n",
       "2  2019-02-12         4  2019-01-30   running       s1_rb   \n",
       "\n",
       "                                   uuid  \n",
       "0  6aeb9274-2482-11e9-bf35-9cb6d020b9c2  \n",
       "1  6aebb77a-2482-11e9-a778-9cb6d020b9c2  \n",
       "2  6aebb77b-2482-11e9-812b-9cb6d020b9c2  "
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin.subscribed_strategy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "account test1 save\n",
      "account test2 save\n",
      "account test3_future save\n"
     ]
    }
   ],
   "source": [
    "admin.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'RB_PORTFOLIO': < QA_Portfolio RB_PORTFOLIO with 3 Accounts >}"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin.portfolio_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "#admin.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>cash</th>\n",
       "      <th>order_id</th>\n",
       "      <th>realorder_id</th>\n",
       "      <th>trade_id</th>\n",
       "      <th>account_cookie</th>\n",
       "      <th>commission</th>\n",
       "      <th>tax</th>\n",
       "      <th>message</th>\n",
       "      <th>frozen</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2019-01-25</td>\n",
       "      <td>000001</td>\n",
       "      <td>20</td>\n",
       "      <td>2000</td>\n",
       "      <td>159990.0</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>test1</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     datetime    code  price  amount      cash order_id realorder_id trade_id  \\\n",
       "0  2019-01-25  000001     20    2000  159990.0     None         None     None   \n",
       "\n",
       "  account_cookie  commission  tax message  frozen  \n",
       "0          test1        10.0    0    None       0  "
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "admin['RB_PORTFOLIO']['test1'].history_table\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "# ## 考虑一个问题:\n",
    "\n",
    "# for p in admin.portfolio_list.values():\n",
    "#     print(p)\n",
    "#     for a in p.accounts.values():\n",
    "#         print(a)\n",
    "#         a.save()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
